<?php


namespace app\repository\Websocket;


use app\model\RoomDevice;
use app\model\WebsocketMsg;

class TcpRepository extends BaseRepository
{
    public static $command = [
        "open_door",
        "open_light_1",
        "open_light_2",
        "open_light_3",
        "open_light_4",
        "open_light_5",
        "open_light_6",
        "open_control_7",
        "open_control_8",
        "open_control_9",
        "open_control_10",
        "open_control_11",
        "open_control_12",
        "open_control_13",
        "open_control_14",
        "open_control_15",
        "open_control_16",
        "open_control_all",
        "close_door",
        "close_light_1",
        "close_light_2",
        "close_light_3",
        "close_light_4",
        "close_light_5",
        "close_light_6",
        "close_control_7",
        "close_control_8",
        "close_control_9",
        "close_control_10",
        "close_control_11",
        "close_control_12",
        "close_control_13",
        "close_control_14",
        "close_control_15",
        "close_control_16",
        "close_control_all",
    ];

    public static function receive($data)
    {
        WebsocketMsg::query()->create([
            "data"=>$data
        ]);
    }

    public static function checkIp($ip)
    {
        return RoomDevice::query()->where("tcp_ip", $ip)->exists();
    }

    public static function check_function($function):bool
    {
        return in_array($function,self::$command);
    }

}